package Main;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Try5 {
    public static void main(String[] args) throws IOException {
        List<Integer> numberList = getList(100);

        List<String> mineList = new ArrayList<>();

        String dirPath = "D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\source";
        File dir = new File(dirPath);
        dir.mkdir();

        dirPath = "D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\target";
        dir = new File(dirPath);
        dir.mkdir();

        dirPath = "D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\mine";
        dir = new File(dirPath);
        dir.mkdir();

        dirPath = "D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\swapnet";
        dir = new File(dirPath);
        dir.mkdir();

        mineList = new ArrayList<>();
        for (int j=0;j<1;j++){
            for (int i=0;i<numberList.size();i++){
                mineList.add("\"img/source/"+numberList.get(i)+".png\"");

            }
        }

        File writeFile = new File("D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\source.txt");
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writeFile)));
        bufferedWriter.write(mineList.toString());
        bufferedWriter.close();
        System.out.println(mineList);

        mineList = new ArrayList<>();
        for (int j=0;j<1;j++){
            for (int i=0;i<numberList.size();i++){
                mineList.add("\"img/target/"+numberList.get(i)+".png\"");
            }
        }
        writeFile = new File("D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\target.txt");
        bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writeFile)));
        bufferedWriter.write(mineList.toString());
        bufferedWriter.close();
        System.out.println(mineList);

        List<String> BList = new ArrayList<>();
        for (int i=0;i<numberList.size();i++){
            BList.add("\"img/swapnet/"+numberList.get(i)+".png\"");
        }

        List<String> AList = new ArrayList<>();
        for (int i=0;i<numberList.size();i++){
            AList.add("\"img/mine/"+numberList.get(i)+".png\"");
        }

        List<String> CList = new ArrayList<>();
        List<String> DList = new ArrayList<>();

        for (int i=0;i<AList.size();i++){
            int b = (int) (Math.random()*(4));
//            System.out.println(b);
            if (b<=1){
                CList.add(AList.get(i));
                DList.add(BList.get(i));
            }else {
                CList.add(BList.get(i));
                DList.add(AList.get(i));
            }
        }
        System.out.println(CList);
        System.out.println(DList);
        writeFile = new File("D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\A.txt");
        bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writeFile)));
        bufferedWriter.write(CList.toString());
        bufferedWriter.close();

        writeFile = new File("D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\B.txt");
        bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writeFile)));
        bufferedWriter.write(DList.toString());
        bufferedWriter.close();


        for (int i=0;i<numberList.size();i++){
            copyFile("D:\\result\\final_result\\outfitlevel\\test_result\\img\\source\\"+numberList.get(i)+".png","D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\source\\"+numberList.get(i)+".png");
            copyFile("D:\\result\\final_result\\outfitlevel\\test_result\\img\\target\\"+numberList.get(i)+".png","D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\target\\"+numberList.get(i)+".png");
            copyFile("D:\\result\\final_result\\outfitlevel\\test_result\\img\\mine\\"+numberList.get(i)+".png","D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\mine\\"+numberList.get(i)+".png");
            copyFile("D:\\result\\final_result\\outfitlevel\\test_result\\img\\swapnet\\"+numberList.get(i)+".png","D:\\result\\final_result\\outfitlevel\\test_result\\img\\img\\swapnet\\"+numberList.get(i)+".png");

        }



    }

    public static List<Integer> getList(int count){
        List<Integer> list = new ArrayList<>();
        for (int i=0;i<count;i++){
            list.add((int) (Math.random()*(9000)));
        }
        return list;
    }

    public static void copyFile(String oldPath, String newPath) {
        try {
            int bytesum = 0;
            int byteread = 0;
            File oldfile = new File(oldPath);
            if (oldfile.exists()) { //文件存在时
                InputStream inStream = new FileInputStream(oldPath); //读入原文件
                FileOutputStream fs = new FileOutputStream(newPath);
                byte[] buffer = new byte[1444];
                int length;
                while ((byteread = inStream.read(buffer)) != -1) {
                    bytesum += byteread; //字节数 文件大小
                    System.out.println(bytesum);
                    fs.write(buffer, 0, byteread);
                }
                inStream.close();
            }
        } catch (Exception e) {
            System.out.println("复制单个文件操作出错");
            e.printStackTrace();

        }
    }

}
